﻿using Kendo.Mvc.Extensions;
using Kendo.Mvc.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using CallCenter.Data;
using CallCenter.Data.BizUtilities;
using System.Configuration;
using System.Data;
using CallCenter.Security;
using CallCenter.Data.Models;
using CallCenter.Data.Misc;
//using iTextSharp.text.pdf;
//using iTextSharp.text;
using System.Globalization;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Web.Caching;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.Web.UI.WebControls;
namespace CallCenter.Web.Controllers
{
    public class InvoiceItemsController : BaseController
    {
        // GET: InvoiceItems
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult InvoiceHistory()
        {
            InvoiceItemsVM cmpy = new InvoiceItemsVM();
            return View(cmpy);
        }
        public JsonResult GetInvoiceItems(int id)
        {
            var scratchPads = this.Bridge.InvoiceItemsUtility.GetAllInvoiceItemByInvoiceId(id);
            return Json(scratchPads, JsonRequestBehavior.AllowGet);
        }

           
        [HttpPost]
        public JsonResult CreateInvoiceItems(InvoiceItemsVM model)
        {
           
           
            var returnMessage = this.Bridge.InvoiceItemsUtility.InsertToInvoiceItems(model); ;
            if (!returnMessage.Status)
                ModelState.AddModelError("Error", returnMessage.Message);
            else {
                return Json(new AjaxSuccess { Message = "Success" }, JsonRequestBehavior.AllowGet);
            }
          
            return Json(new AjaxFailure { Errors = ModelState.SerializeErrors }, JsonRequestBehavior.DenyGet);
        }

        [HttpPost]
        public JsonResult DeleteInvoiceItems(InvoiceItemsVM model)
        {
            //insert items into respective tables
            int id = model.id;
            this.Bridge.InvoiceItemsUtility.Delete(id);
            var returnMessage = "Success";
            return Json(returnMessage, JsonRequestBehavior.AllowGet);

        }

        [HttpPost]
        public JsonResult UpdateInvoiceItems(InvoiceItemsVM model)
        {
            var result = this.Bridge.InvoiceItemsUtility.UpdateToInvoiceItems(model);
            return Json(result, JsonRequestBehavior.AllowGet);
        }



    }
}